<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Verify;
class HomeController extends Controller {
  
  public function login(){
		header("Content-Type:text/html; charset=utf-8");
    	if (IS_POST) {
    		
	    	$finduse['name'] = trim(I('post.name'));
			 
			$finduse['pwd']  = myencode(I('post.pwd'),5,5);
			//echo json_encode(array('message'=>$finduse['pwd']));exit();
			$verCode = trim(I('post.yzm'));//验证码
			
			//$this->check_verify($verCode)
			if(!$this->check_verify($verCode)){
				echo json_encode(array('message'=>'验证码错误，请重新输入！'));exit();
				
			}else{
				$user = M('member')->where(array('name'=>$finduse['name']))->find();
				
				if($user){
					$succuse = M('member')->where(array('name'=>$finduse['name'],'pwd'=> $finduse['pwd']))->find();
					if($succuse){
						session('adminuser',$succuse['name']);
						//session('adminqx',$user['mb_right']);
						echo json_encode(array('message'=>'登录成功！'));exit();
					}else{
						echo json_encode(array('message'=>'密码输入错误，请重新输入！'));exit();
					}
				}else{
					echo json_encode(array('message'=>'账号输入错误，请重新输入！'));exit();
				}
		  }
		 
    	
    	}
      $this->display();
  }
	
	
	public function loginout(){
		
		
		session_unset();
    	session_destroy();
		 $this->display('login');
	}

    // 验证码
    public function verify(){
      ob_clean();

        $config =    array(
            'fontSize'    =>    18,    // 验证码字体大小
            'length'      =>    4,     // 验证码位数
            'useNoise'    =>    false, // 关闭验证码杂点
            'imageW'      =>    140,    //验证码宽度
            'imageH'      =>    35,    //验证码宽度
            'bg'          =>    array(243, 251, 254),    //验证码背景颜色 rgb数组设置，例如 array(243, 251, 254)
            'useCurve'  =>  false //// 是否画混淆曲线
        );
        $Verify = new \Think\Verify($config);
        $Verify->entry();
    }

    //检验 验证码
    public function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
    }
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}